#include<iostream>
#include<string>
#include "bintree.h"
TNode* ordered_list;

void convert_node(TNode *pnode,TNode* &plast){
    if(pnode == NULL)
        return;
    TNode *pc = pnode;
    if(pc->left != NULL)
        convert_node(pc->left,plast);
    //put the current node into the double-linked list
    pc->left = plast;
    if(plast)
        plast->right = pc;
    plast = pc;
    if(pc->right)
        convert_node(pc->right,plast);
}

TNode* convert(BinTree root){
    TNode *phead,*plast  = NULL;
    convert_node(root,plast);
    phead = plast;
    while(phead && phead->left)
        phead = phead->left;
    return phead;
}

int main(){
    BinTree root;
    TNode* head;
    create_tree(&root);
    head = convert(root);
    while(head){
        printf("%c ",head->data);
        head = head->right;
    }
    return 0;
}

